
<title>文章列表</title>

<div class="layui-card layadmin-header">
  <div class="layui-breadcrumb" lay-filter="breadcrumb">
    <a lay-href="">主页</a>
    <a><cite>文章管理</cite></a>
    <a><cite>文章列表</cite></a>
  </div>
</div>

<div class="layui-fluid">
  <div class="layui-card">
    <div class="layui-form layui-card-header layuiadmin-card-header-auto" lay-filter="app-forum-list">
      <div class="layui-form-item">
        <div class="layui-inline">
          <label class="layui-form-label">标题</label>
          <div class="layui-input-block">
            <input type="text" name="q" placeholder="请输入" autocomplete="off" class="layui-input">
          </div>
        </div>
        <div class="layui-inline">
          <button class="layui-btn layuiadmin-btn-forum-list" lay-submit lay-filter="LAY-app-forumlist-search">
            <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
          </button>
        </div>
      </div>
    </div>

      <div class="layui-card-body">
        <div style="padding-bottom: 10px;">
          <button class="layui-btn layuiadmin-btn-forum-list"  lay-href="news/newsadd">添加</button>
        </div>
      <table id="LAY-app-forum-list" lay-filter="LAY-app-forum-list"></table>
        <script type="text/html" id="table-forum-list">
        <a class="layui-btn layui-btn-normal layui-btn-xs" lay-href="news/newsedit/id={{d.id}}"><i class="layui-icon layui-icon-edit"></i>编辑</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
      </script>
    </div>
  </div>
</div>

<script>
  layui.use('news', layui.factory('news')).use(['admin', 'news', 'table', 'upload'], function(){
    var $ = layui.$
        ,form = layui.form
        ,view = layui.view
        ,admin = layui.admin
        ,upload = layui.upload
        ,table = layui.table;

    form.render(null, 'app-forum-list');

    //监听搜索
    form.on('submit(LAY-app-forumlist-search)', function(data){
      var field = data.field;

      //执行重载
      table.reload('LAY-app-forum-list', {
        where: field
      });
    });
    form.on('switch(changeStatus)', function(data){
      if(this.checked){
        var status = 1;
      }else{
        var status = 0;
      }
      var $=layui.$;
      var id = $(this).attr('data-id');
      var type = $(this).attr('data-type');
      if(id > 0){
        var index = layer.load(1, {
          shade: [0.1,'#fff'] //0.1透明度的白色背景
        });
        admin.req({
          url: layui.setter.api+'news/news'
          ,data: {'id':id,'val':status,'opt':type}
          ,method:'post'
          ,success: function(data){
            layer.close(index);
          }
        });
        return false;
      }else{
        layer.msg('数据有误，请刷新重试',{ shift: -1, time: 1500 });
      }
    });
  });
</script>